from LeetCoder import *


class Solution:

    def minCost(self, nums: List[int], x: int) -> int:
        n = len(nums)
        mn = [[inf] * n for _ in range(n)]
        mn[0] = nums.copy()
        for i in range(1, n):
            for j in range(n):
                mn[i][j] = min(mn[i - 1][j], nums[(j + i) % n])
        ans = inf
        for i in range(n):
            ans = min(ans, sum(mn[i]) + i * x)
        return ans


s = Solution()
print(s.minCost(nums=[20, 1, 15], x=5))
